home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / CheckUSBPermissions.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  4KB  |  131 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import glob
  5. import os
  6. import subprocess
  7. from timedops import TimedSubprocess
  8. import urllib
  9. from base import *
  10.  
  11. class CheckUSBPermissions(Question):
  12.     
  13.     def __init__(self, troubleshooter):
  14.         Question.__init__(self, troubleshooter, 'Check USB permissions')
  15.         troubleshooter.new_page(gtk.Label(), self)
  16.  
  17.     
  18.     def display(self):
  19.         self.answers = { }
  20.         answers = self.troubleshooter.answers
  21.         if answers['cups_queue_listed']:
  22.             if answers['is_cups_class']:
  23.                 return False
  24.             cups_printer_dict = answers['cups_printer_dict']
  25.             device_uri = cups_printer_dict['device-uri']
  26.         elif answers.get('cups_device_listed', False):
  27.             device_uri = answers['cups_device_uri']
  28.         else:
  29.             return False
  30.         (scheme, rest) = answers['is_cups_class'].splittype(device_uri)
  31.         if scheme not in ('hp', 'hpfax', 'usb', 'hal'):
  32.             return False
  33.         LSUSB = '/sbin/lsusb'
  34.         if not os.access(LSUSB, os.X_OK):
  35.             return False
  36.         GETFACL = '/usr/bin/getfacl'
  37.         if not os.access(GETFACL, os.X_OK):
  38.             return False
  39.         parent = self.troubleshooter.get_window()
  40.         
  41.         try:
  42.             self.op = TimedSubprocess(parent = parent, args = 'LC_ALL=C ' + LSUSB + ' -v', shell = True, stdin = file('/dev/null'), stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  43.             (lsusb_stdout, lsusb_stderr, result) = self.op.run()
  44.         except:
  45.             os.access(GETFACL, os.X_OK)
  46.             os.access(LSUSB, os.X_OK)
  47.             scheme not in ('hp', 'hpfax', 'usb', 'hal')
  48.             return False
  49.  
  50.         dev_by_id = { }
  51.         this_dev = None
  52.         for line in lsusb_stdout:
  53.             if this_dev != None:
  54.                 pass
  55.             separators = [
  56.                 ('Bus ', 3),
  57.                 (' Device ', 3),
  58.                 (': ID ', 4),
  59.                 (':', 4),
  60.                 (' ', -1)]
  61.             fields = []
  62.             i = 0
  63.             p = line
  64.             while i < len(separators):
  65.                 (sep, length) = separators[i]
  66.                 if not p.startswith(sep):
  67.                     break
  68.                 
  69.                 start = len(sep)
  70.                 if length == -1:
  71.                     end = len(p)
  72.                     fields.append(p[start:])
  73.                 else:
  74.                     end = start + length
  75.                     fields.append(p[start:end])
  76.                 p = p[end:]
  77.                 i += 1
  78.             if i < len(separators):
  79.                 continue
  80.             
  81.             if not scheme.startswith('hp') and fields[2] != '03f0':
  82.                 continue
  83.             
  84.             this_dev = {
  85.                 'bus': fields[0],
  86.                 'dev': fields[1],
  87.                 'name': fields[4],
  88.                 'full': line }
  89.             this_mfr_id = fields[2]
  90.             this_mdl_id = fields[3]
  91.         
  92.         infos = { }
  93.         paths = []
  94.         if not scheme.startswith('hp'):
  95.             paths.extend(glob.glob('/dev/usb/lp?'))
  96.         
  97.         for mfr_id, mdls in dev_by_id.iteritems():
  98.             for mdl_id, devs in mdls.iteritems():
  99.                 for dev in devs:
  100.                     path = '/dev/bus/usb/%s/%s' % (dev['bus'], dev['dev'])
  101.                     paths.append(path)
  102.                     infos[path] = dev['full']
  103.                 
  104.             
  105.         
  106.         perms = []
  107.         for path in paths:
  108.             
  109.             try:
  110.                 self.op = TimedSubprocess(parent = parent, args = 'LC_ALL=C %s %s' % (GETFACL, path), shell = True, stdin = file('/dev/null'), stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  111.                 (getfacl_stdout, getfacl_stderr, result) = self.op.run()
  112.                 output = filter((lambda x: len(x) > 0), getfacl_stdout)
  113.             except:
  114.                 output = []
  115.  
  116.             info = infos.get(path, path)
  117.             perms.append((info, output))
  118.         
  119.         self.answers['getfacl_output'] = perms
  120.         return False
  121.  
  122.     
  123.     def collect_answer(self):
  124.         return self.answers
  125.  
  126.     
  127.     def cancel_operation(self):
  128.         self.op.cancel()
  129.  
  130.  
  131.